package com.djinfo.work.dao.impl;

import com.djinfo.work.common.dao.impl.BaseDaoImpl;
import com.djinfo.work.dao.QsContentDao;
import com.djinfo.work.entity.QsContentEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 * @date 2017-06-08 10:48:16
 */
@Repository("QsContentDao")
public class QsContentDaolmpl extends BaseDaoImpl implements com.djinfo.work.dao.QsContentDao {

    @Override
    public void save(QsContentEntity object) {
        if(null==object.getId()){
            super.save(object);
        }else{
            super.update(object);
        }
    }

    @Override
    public void update(QsContentEntity qsContentEntity) {
        super.update(qsContentEntity);
    }

    @Override
    public QsContentEntity selectOne(String id) {
        return (QsContentEntity)super.getByPrimaryKey(QsContentEntity.class,id);
    }

    @Override
    public void delete(String id) {
        QsContentEntity qsContentEntity = (QsContentEntity)super.getByPrimaryKey(QsContentEntity.class,id);
        super.delete(qsContentEntity);
    }

    @Override
    public List<QsContentEntity> page(QsContentEntity object, Integer pageNum, Integer pageSize) {
        String hql="";
        if(object.getValue()==""||object.getValue()==null){
            hql = " from QsContentEntity where 1=1 ";
        }else {
            hql = " from QsContentEntity where value like '%"+ object.getValue()+ "%'";
        }
        return (List<QsContentEntity>)super.pageQuery( hql,  pageNum,  pageSize);
    }

    @Override
    public Integer getRowCount(QsContentEntity object) {
        String hql="";
        if("".equals(object.getValue())||object.getValue()==null){
            hql="select count(*) from QsContentEntity";
        }else {
            hql="select count(*) from QsContentEntity where value like '%"+ object.getValue()+ "%'";
        }

        return super.getUniqueObject(hql).hashCode();
    }

    @Override
    public List<QsContentEntity> getByTitleId(String hql,String id) {
        return super.getList(hql,id);
    }
}
